//
//  YHMerchantMoveViewController.m
//  YHApp
//
//  Created by -- on 2021/6/25.
//

#import "HAMerchantMoveVC.h"
#import "HASMSendVC.h"
#import "HAMerchantMoveMo.h"
#import "HAMerchantMoveAgPopView.h"
#import "HAChooseTabPopView.h"

@interface HAMerchantMoveVC ()
<UITextFieldDelegate,UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic ,strong) NSMutableArray *dataArray;

/***/
@property (nonatomic, strong) UIImageView *s1ImgV;
/***/
@property (nonatomic, strong) UIImageView *s2ImgV;
/***/
@property (nonatomic, strong) UIImageView *s3ImgV;
/***/
@property (nonatomic, strong) UILabel *t1Label;
/***/
@property (nonatomic, strong) UILabel *t2Label;
/***/
@property (nonatomic, strong) UILabel *t3Label;
/***/
@property (nonatomic, strong) UITextField *seachField;

/***/
@property (nonatomic, assign) NSInteger type;
/***/
@property (nonatomic, strong) HAMerchantMoveAgentsMo *selModel;

/***/
@property (nonatomic, strong) HAMerchantMoveMo *model;

@end

@implementation HAMerchantMoveVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.baseTLabel.text = @"商户转移";
    
    [self setupUI];
    
    self.type = 1;

    // Do any additional setup after loading the view.
}

-(void)scanSodeBtnClick {
    [self.view endEditing:YES];
    
    WS(weakSelf)
    if ([HAHelper isCamera]) {
        HASMSendVC *vc = [[HASMSendVC alloc]init];
        [vc retrunBlock:^(NSString * _Nonnull snText) {
            weakSelf.seachField.text = snText;
//            [weakSelf seachProduct:snText];
        }];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        HATipsPopView *menu = [[HATipsPopView alloc]initWithTitle:@"温馨提示" content:@"请允许访问您的相机" left:@"取消" right:@"去设置"];
        [menu show];
        menu.XZYGTiShiRightBlock = ^{
            [HAHelper GetPhoneSet];
        };
    }
}

-(void)seachBtnClick {
    [self.view endEditing:YES];
    
    if ([NSString isEmptyString:self.seachField.text]) {
        [MBProgressHUD showError:@"请输入机具SN"];
        return;
    }
    [self loadDataWith:self.seachField.text];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self.view endEditing:YES];

    if ([NSString isEmptyString:self.seachField.text]) {
        [MBProgressHUD showError:@"请输入机具SN"];
        return NO;
    }

    [self loadDataWith:self.seachField.text];
    
    return YES;
}

-(void)leftBtnClick {
    if (self.type == 2) {
        self.type = 1;
    }
    if (self.type == 3) {
        self.type = 2;
    }
}

-(void)rightBtnClick {
    if (self.type == 2) {
        self.type = 3;
    }else if (self.type == 3) {
        [self mitButtonClick];
    }
}

-(void)setType:(NSInteger)type {
    _type = type;
    if (_type == 1) {
        self.s1ImgV.image = [UIImage imageNamed:@"ha_1_sel"];
        self.s2ImgV.image = [UIImage imageNamed:@"ha_1_def"];
        self.s3ImgV.image = [UIImage imageNamed:@"ha_1_def"];

        self.t1Label.textColor = [UIColor colorWithHexString:@"#21252a"];
        self.t2Label.textColor = [UIColor colorWithHexString:@"#858b9c"];
        self.t3Label.textColor = [UIColor colorWithHexString:@"#858b9c"];
                
        [self.dataArray removeAllObjects];
        [self.dataArray addObject:@"搜索"];
        [self.tableView reloadData];

    }else if (_type == 2) {
        self.s1ImgV.image = [UIImage imageNamed:@"ha_1_def"];
        self.s2ImgV.image = [UIImage imageNamed:@"ha_1_sel"];
        self.s3ImgV.image = [UIImage imageNamed:@"ha_1_def"];

        self.t1Label.textColor = [UIColor colorWithHexString:@"#858b9c"];
        self.t2Label.textColor = [UIColor colorWithHexString:@"#21252a"];
        self.t3Label.textColor = [UIColor colorWithHexString:@"#858b9c"];

        [self.dataArray removeAllObjects];
        [self.dataArray addObject:@"商户名称"];
        [self.dataArray addObject:@"商户手机号"];
        [self.dataArray addObject:@"机具SN"];
        [self.dataArray addObject:@"下一步"];
        [self.tableView reloadData];

    }else if (_type == 3) {
        self.s1ImgV.image = [UIImage imageNamed:@"ha_1_def"];
        self.s2ImgV.image = [UIImage imageNamed:@"ha_1_def"];
        self.s3ImgV.image = [UIImage imageNamed:@"ha_1_sel"];

        self.t1Label.textColor = [UIColor colorWithHexString:@"#858b9c"];
        self.t2Label.textColor = [UIColor colorWithHexString:@"#858b9c"];
        self.t3Label.textColor = [UIColor colorWithHexString:@"#21252a"];

        [self.dataArray removeAllObjects];
        [self.dataArray addObject:@"选择代理"];
        [self.dataArray addObject:@"下一步"];
        [self.tableView reloadData];
    }
}

-(void)setupUI {
    
    UIView *bgV = [UIView ha_createView];
    bgV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgV];
    [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(app_topH+44+1);
        make.height.mas_offset(92);
    }];
    
    UIImageView *s1ImgV = [UIImageView ha_createImageView];
    self.s1ImgV = s1ImgV;
    s1ImgV.image = [UIImage imageNamed:@"ha_1_sel"];
    [bgV addSubview:s1ImgV];
    
    UIImageView *s2ImgV = [UIImageView ha_createImageView];
    self.s2ImgV = s2ImgV;
    s2ImgV.image = [UIImage imageNamed:@"ha_1_def"];
    [bgV addSubview:s2ImgV];

    UIImageView *s3ImgV = [UIImageView ha_createImageView];
    self.s3ImgV = s3ImgV;
    s3ImgV.image = [UIImage imageNamed:@"ha_1_def"];
    [bgV addSubview:s3ImgV];

    UIView *line1V = [UIView ha_createView];
    line1V.backgroundColor = [UIColor khaBGColor];
    [bgV addSubview:line1V];
    
    UIView *line2V = [UIView ha_createView];
    line2V.backgroundColor = [UIColor khaBGColor];
    [bgV addSubview:line2V];

    UILabel *t1Label = [UILabel ha_NLabelWithFont:15 textColor:@"#21252a" text:@"序列号" alignment:1];
    self.t1Label = t1Label;
    [bgV addSubview:t1Label];
    
    UILabel *t2Label = [UILabel ha_NLabelWithFont:15 textColor:@"#858b9c" text:@"商户信息" alignment:1];
    self.t2Label = t2Label;
    [bgV addSubview:t2Label];

    UILabel *t3Label = [UILabel ha_NLabelWithFont:15 textColor:@"#858b9c" text:@"选择代理" alignment:1];
    self.t3Label = t3Label;
    [bgV addSubview:t3Label];
    
    [s2ImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(16);
        make.height.mas_offset(16);
        make.top.mas_equalTo(25);
        make.centerX.mas_equalTo(0);
    }];
    
    [s1ImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(16);
        make.height.mas_offset(16);
        make.top.mas_equalTo(25);
        make.left.mas_equalTo(42);
    }];
    
    [s3ImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(16);
        make.height.mas_offset(16);
        make.top.mas_equalTo(25);
        make.right.mas_equalTo(-42);
    }];
    
    [line1V mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(s1ImgV.mas_right).offset(10);
        make.right.mas_equalTo(s2ImgV.mas_left).offset(-10);
        make.centerY.mas_equalTo(s2ImgV);
        make.height.mas_offset(1);
    }];
    
    [line2V mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(s2ImgV.mas_right).offset(10);
        make.right.mas_equalTo(s3ImgV.mas_left).offset(-10);
        make.centerY.mas_equalTo(s2ImgV);
        make.height.mas_offset(1);
    }];
    
    [t1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(s1ImgV);
        make.top.mas_equalTo(s1ImgV.mas_bottom).offset(12);
    }];

    [t2Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(s2ImgV);
        make.top.mas_equalTo(s2ImgV.mas_bottom).offset(12);
    }];

    [t3Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(s3ImgV);
        make.top.mas_equalTo(s3ImgV.mas_bottom).offset(12);
    }];

    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgV.mas_bottom);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];

}


-(void)loadDataWith:(NSString *)key {
    WS(weakSelf)
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodPOST;
    request.requestUrl = @"customer/cuss";
    request.parms = @{
        @"keyword":key,
    };

    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                if ([dataModel.data isKindOfClass:[NSArray class]]) {
                    NSArray *arr = dataModel.data;
                    if (arr.count > 0) {
                        NSMutableArray *dicts = [NSMutableArray array];
                        for (int i = 0; i < arr.count; i++) {
                            NSDictionary *dict = arr[i];
                            NSString *name = @"";
                            if ([[dict allKeys] containsObject:@"surname"]) {
                                name = [NSString stringWithFormat:@"%@", dict[@"surname"]];
                            }
                            NSString *term_sn = @"";
                            if ([[dict allKeys] containsObject:@"term_sn"]) {
                                term_sn = [NSString stringWithFormat:@"%@", dict[@"term_sn"]];
                            }
                            [dicts addObject:@{@"color":@"#373737",@"title":name,@"term_sn":term_sn,}];
                        }
                        if (dicts.count == 1) {
                            [weakSelf seachProductSn:dicts.firstObject[@"term_sn"]];
                        }
                        if (dicts.count > 1) {
                            HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"请选择商户"];
                            menu.YHChooseTabMenuCellSureBlock = ^(NSDictionary * _Nonnull dic) {
                                [weakSelf seachProductSn:dic[@"term_sn"]];
                            };
                            [menu show];
                        }

//                        HAChooseTabPopView *menu = [[HAChooseTabPopView alloc]initWithDicts:dicts title:@"请选择商户"];
//                        menu.YHChooseTabMenuCellSureBlock = ^(NSDictionary * _Nonnull dic) {
//                            [weakSelf seachProductSn:dic[@"term_sn"]];
//                        };
//                        [menu show];
                    }
                }
                
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];

}

-(void)seachProductSn:(NSString *)sn {
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodGET;
    request.requestUrl = @"product/transfer";
    request.parms = @{
        @"sn":sn,
    };
    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                self.model = [HAMerchantMoveMo mj_objectWithKeyValues:dataModel.data];
                if (self.model) {
                    self.type = 2;
                }
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];

}

-(void)mitButtonClick {

    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodPOST;
    request.requestUrl = [NSString stringWithFormat:@"product/transfer?step=2"];
    request.parms = @{
        @"agent_id":self.selModel.value?:@"",
        @"sn":self.model.customer.sn?:@"",
        @"step":@"2",
    };
    [MBProgressHUD showLoading:self.view];

    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                [MBProgressHUD showSuccess:@"提交成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    id model = self.dataArray[indexPath.row];
    if ([model isKindOfClass:[NSString class]]) {
        if ([model isEqualToString:@"搜索"]) {
            return 95;
        }
        if ([model isEqualToString:@"商户名称"]||[model isEqualToString:@"商户手机号"]||[model isEqualToString:@"机具SN"]) {
            return 70;
        }
        if ([model isEqualToString:@"选择代理"]) {
            return 54+28;
        }
        if ([model isEqualToString:@"下一步"]) {
            return 65+54;
        }
    }
    return 0;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    id model = self.dataArray[indexPath.row];
    if ([model isKindOfClass:[NSString class]]) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHMerchantMoveSeachCellID"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YHMerchantMoveSeachCellID"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if ([model isEqualToString:@"搜索"]) {
            [self setCellSeash:cell.contentView];
        }
        if ([model isEqualToString:@"商户名称"]) {
            [self setCustomerCell:cell.contentView title:model content:self.model.customer.surname];
        }
        if ([model isEqualToString:@"商户手机号"]) {
            [self setCustomerCell:cell.contentView title:model content:self.model.customer.mobile];
        }
        if ([model isEqualToString:@"机具SN"]) {
            [self setCustomerCell:cell.contentView title:model content:self.model.customer.sn];
        }
        if ([model isEqualToString:@"选择代理"]) {
            NSString *content = @"选择代理";
            if (self.selModel) {
                content = self.selModel.text;
            }
            [self setAgentCell:cell.contentView content:content];
        }
        if ([model isEqualToString:@"下一步"]) {
            [self setNextCell:cell.contentView];
        }

        return cell;
    }
    return [UITableViewCell new];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    WS(weakSelf)
    id model = self.dataArray[indexPath.row];
    if ([model isKindOfClass:[NSString class]]) {
        if ([model isEqualToString:@"选择代理"]) {
            HAMerchantMoveAgPopView *menu = [[HAMerchantMoveAgPopView alloc]initWithTitle:@"选择代理" array:self.model.agents];
            [menu show];
            menu.YHMerchantMoveAgSureBlock = ^(HAMerchantMoveAgentsMo * _Nonnull model) {
                weakSelf.selModel = model;
                [weakSelf.tableView reloadData];
            };
        }
    }
}

-(void)setCellSeash:(UIView *)contentView {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }

    contentView.backgroundColor = [UIColor whiteColor];
    
    UIButton *scanSodeBtn = [[UIButton alloc]init];
    [scanSodeBtn setImage:[UIImage imageNamed:@"ha_11"] forState:UIControlStateNormal];
    [scanSodeBtn addTarget:self action:@selector(scanSodeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:scanSodeBtn];
    [scanSodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(22);
        make.height.mas_offset(22);
    }];

    UIButton *seachBtn = [[UIButton alloc]init];
    [seachBtn setImage:[UIImage imageNamed:@"ha_searchIcon"] forState:UIControlStateNormal];
    [seachBtn addTarget:self action:@selector(seachBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:seachBtn];
    [seachBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(22);
        make.height.mas_offset(22);
    }];

    UITextField *seachField = [[UITextField alloc]init];
    self.seachField = seachField;
    seachField.delegate = self;
    seachField.placeholder = @"请输入机具SN";
    seachField.font = [UIFont systemFontOfSize:18];
    seachField.returnKeyType = UIReturnKeySearch;
    [contentView addSubview:seachField];
    [seachField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(scanSodeBtn.mas_right).offset(15);
        make.right.equalTo(seachBtn.mas_left).offset(-15);
        make.centerY.mas_equalTo(0);
        make.height.equalTo(@28);
    }];
}

-(void)setCustomerCell:(UIView *)contentView title:(NSString *)title content:(NSString *)content {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }

    contentView.backgroundColor = [UIColor whiteColor];

    UILabel *titlabel = [UILabel ha_NLabelWithFont:12 textColor:@"#828b9c" text:title alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(12);
    }];

    UILabel *conlabel = [UILabel ha_BLabelWithFont:17 textColor:@"#828b9c" text:content alignment:0];
    [contentView addSubview:conlabel];
    [conlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titlabel.mas_bottom).offset(10);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(18);
    }];

    UIView *lineView = [UIView ha_createView];
    lineView.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(1);
        make.bottom.mas_equalTo(0);
    }];

}

-(void)setAgentCell:(UIView *)contentView content:(NSString *)content {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }

    contentView.backgroundColor = [UIColor whiteColor];

    UILabel *titlabel = [UILabel ha_NLabelWithFont:17 textColor:@"#000000" text:@"代理" alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(20);
        make.width.mas_offset(72);
        make.height.mas_offset(18);
    }];

    UIImageView *RImgV = [UIImageView ha_createImageView];
    RImgV.image = [UIImage imageNamed:@"ic_cell_more"];
    [contentView addSubview:RImgV];
    [RImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(5);
        make.height.mas_offset(10);
        make.centerY.mas_equalTo(titlabel);
        make.right.mas_equalTo(-20);
    }];

    UILabel *conlabel = [UILabel ha_BLabelWithFont:16 textColor:@"#111A34" text:content alignment:2];
    [contentView addSubview:conlabel];
    [conlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titlabel.mas_right).offset(10);
        make.centerY.mas_equalTo(titlabel);
        make.right.mas_equalTo(RImgV.mas_left).offset(-15);
    }];

    UIView *lineView = [UIView ha_createView];
    lineView.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(1);
        make.bottom.mas_equalTo(-27);
    }];

}

-(void)setNextCell:(UIView *)contentView {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }

    contentView.backgroundColor = [UIColor khaBGColor];

    UIButton *leftBtn = [[UIButton alloc]init];
    [leftBtn setTitle:@"上一步" forState:UIControlStateNormal];
    [leftBtn setTitleColor:[UIColor colorWithHexString:@"#5f67fc"] forState:UIControlStateNormal];
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    leftBtn.layer.borderColor = [UIColor colorWithHexString:@"#5f67fc"].CGColor;
    leftBtn.layer.borderWidth = 0.6;
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(-70);
        make.bottom.mas_equalTo(0);
        make.width.mas_offset(118);
        make.height.mas_offset(54);
    }];

    UIButton *rightBtn = [[UIButton alloc]init];
    [rightBtn setTitleColor:[UIColor colorWithHexString:@"@ffffff"] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    rightBtn.backgroundColor = [UIColor colorWithHexString:@"#191919"];
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(70);
        make.bottom.mas_equalTo(0);
        make.width.mas_offset(118);
        make.height.mas_offset(54);
    }];
    
    if (self.type == 2) {
        [rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
    }
    if (self.type == 3) {
        [rightBtn setTitle:@"确定" forState:UIControlStateNormal];
    }
    
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        // 去掉滚动条
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;

        // 设置背景颜色
        _tableView.backgroundColor = [UIColor khaBGColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}



@end
